import { tooltip, seriesConfig, legendConfig } from './pieParams'

// 告警处理状态饼图
export const alarmPie = (done, yet) => {
  let color = []
  console.log('告警处理状态饼图:', done, yet)
  let txt = ''
  if ((done + yet) <= 0) {
    txt = '0%'
  } else {
    let v = done/(done+yet)
    console.log('v:', v)
    let f = v.toFixed(2)
    console.log('f:', f)
    let n = ~~(f * 100)
    console.log('n:', n)
    txt = `${n}%`
  }

  if (done <= 0 && yet <= 0) {
    color = '#2f4159'
  } else {
    color = ['#9bc8df', '#ff2f00']
  }

  const { clientWidth:w } = document.body

  return {
    title: {
      text: txt,
      subtext: '处理率',
      textAlign: 'center',
      textStyle: {
        color: '#fff',
        fontSize: w/1920 * 40,
        align: 'center',
        rich: {
          align: 'center'
        }
      },
      subtextStyle: {
        color: '#fff',
        fontSize: w/1920 * 20,
        align: 'center',
        rich: {
          align: 'center'
        },
      },
      top: '39%',
      left: '39%'
    },
    tooltip,
    color,
    legend: {
      ...legendConfig,
      data: ['已处理', '未处理']
    },
    series: [
      {
        ...seriesConfig,
        data: [
          {value: done, name: '已处理'},
          {value: yet, name: '未处理'},
        ]
      }
    ]
  }
  
}